package com.ihg.hiex.admin.web.controller.session;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.core.web.utils.WebUtils;
import com.ihg.hiex.admin.entity.security.Login;
import com.ihg.hiex.admin.service.session.SessionService;
import com.ihg.hiex.admin.web.resolver.Secure;
import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.session.Status;

/**
 * 已完成评测
 * 
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("/history-sessions")
@MenuSetting("menu-sessions")
public class HistorySessionController {
    
    @Autowired
    private SessionService sessionService;
    
    /**
     * list all history session
     * 
     * @param login
     * @param page
     * @param request
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-history-sessions-management")
    public ModelAndView list(@Secure Login login, Page page, HttpServletRequest request) {

        ModelAndView modelAndView = new ModelAndView("session/history/session-admin-list");
        
        int totals = sessionService.count(login, Status.HISTORY);
        if (totals > 0) {

            List<Session> sessions = sessionService.list(login, Status.HISTORY, page.with(totals));

            modelAndView.addObject("sessions", sessions);
            modelAndView.addObject("page", page);
            modelAndView.addObject("queryString", WebUtils.extractQueryString(request, "page", "filter"));
            
        }
        
        return modelAndView;
        
    }

    /**
     * search panel.
     * 
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public ModelAndView search() {
        ModelAndView modelAndView = new ModelAndView("session/history/session-search");
        return modelAndView;
    }

    /**
     * search.
     * 
     * @param login
     * @param page
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET, params = "filter")
    @MenuSetting("submenu-history-sessions-management")
    public ModelAndView onSearch(@Secure Login login, Page page) {
        
        ModelAndView modelAndView = new ModelAndView("session/history/session-admin-list");
        
        
        
        return modelAndView;
        
    }
    
}
